﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SMS.Items
{
    public partial class ItemsTransaction : System.Web.UI.Page
    {
        private SMS.Business.Items.ItemTransactionsBusiness ItemTBusinees;
        private List<SMS.DAL.ItemsTransaction> TransFound
        {
            set
            {
                ViewState["TransFound"] = value;
            }
            get
            {
                return (List<SMS.DAL.ItemsTransaction>)ViewState["TransFound"];
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            ItemTBusinees = new Business.Items.ItemTransactionsBusiness();
            Business.Stocks.StocksBusiness SB = new Business.Stocks.StocksBusiness();
            if (!IsPostBack)
            {
                drpStockType.DataSource = SB.Search(new DAL.Providers.StockSearchCriteria() { Name = string.Empty, type = null });
                drpStockType.DataTextField = "Name";
                drpStockType.DataValueField = "ID";
                drpStockType.DataBind();
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            TransFound = ItemTBusinees.Search(new DAL.Providers.ItemTransactionSearchCriteria()
            {
                Barcode = txtBarcode.Text,
                StartDate = CalendarExtender1.SelectedDate,
                EndDate = CalendarExtender2.SelectedDate,
                StockID = drpStockType.SelectedValue == "-1" ? (int?)null: int.Parse(drpStockType.SelectedValue)
            });
            GridView1.DataSource = TransFound;
            GridView1.DataBind();
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {

        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                SMS.DAL.ItemsTransaction temp = (SMS.DAL.ItemsTransaction)e.Row.DataItem;
                if (temp.OrderID == null)
                    e.Row.Cells[2].Text = "قيمة أولية";
                else
                    e.Row.Cells[2].Text = temp.OrderID.ToString();

            }
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.DataSource = TransFound;
            GridView1.PageIndex = e.NewPageIndex;
            this.DataBind();
        }
    }
}